/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketManager.controller;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import ticketManager.ejb.ProductDAO;
import ticketManager.model.ManagerUser;
import ticketManager.model.Product;

/**
 *
 * @author Administrator
 */
@Named
@RequestScoped
public class CreateProductController {
    @EJB
    ProductDAO productDAO;
    
    private String title;

    public ProductDAO getProductDAO() {
        return productDAO;
    }

    public void setProductDAO(ProductDAO productDAO) {
        this.productDAO = productDAO;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    
    public String doCreateProduct()
    {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ManagerUser m = (ManagerUser) facesContext.getExternalContext().getSessionMap().get("user");
        if(!(title.equals("")))
        {
            Product p = productDAO.createProduct(title);
            //create history
            return "success";
        }
        else
        {
            return "failed";
        }
        
    }
}
